package com.itheima.ai.controller;

import com.itheima.ai.repository.ChatHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;

//哄哄模拟器游戏
@RequiredArgsConstructor  // 自动注入构造函数，用于注入final字段（有参构造的一个注解）
@RestController
@RequestMapping("/ai")
public class GameController {
    private final ChatClient gameChatClient;

    //阻塞式
    @RequestMapping(value = "/game",produces = "text/html;charset=utf-8")
    public String chat(String prompt,String chatId) {
        return gameChatClient.prompt()
                .user(prompt)  //设置用户输入
                .advisors(a->a.param(CHAT_MEMORY_CONVERSATION_ID_KEY,chatId))  //设置会话ID
                .call()  //调用模型
                .content();  //获取模型的响应内容
    }
}
